package cn.micro.system.manage.service.impl;

import cn.micro.system.manage.entity.AssetDimTypeInfo;
import cn.micro.system.manage.entity.dto.AssetDimTypeSearch;
import cn.micro.system.manage.mapper.AssetDimTypeInfoMapper;
import cn.micro.system.manage.service.AssetDimTypeInfoService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.function.Consumer;

/**
 * <p>
 * 类型信息 服务实现类
 * </p>
 *
 * @author wr
 * @since 2024-01-05
 */
@Service
public class AssetDimTypeInfoServiceImpl extends ServiceImpl<AssetDimTypeInfoMapper, AssetDimTypeInfo> implements AssetDimTypeInfoService {

    @Override
    public AssetDimTypeInfo detail(Long id) {
        return this.baseMapper.queryById(id);
    }

    @Override
    public List<AssetDimTypeInfo> listByPage(int page, int size, AssetDimTypeSearch search) {
        PageHelper.startPage(page,size);
        return this.baseMapper.queryByPage(search);
    }

    @Override
    public List<AssetDimTypeInfo> getByCodeOrName(AssetDimTypeInfo assetDimTypeInfo) {
        LambdaQueryWrapper<AssetDimTypeInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.and(assetDimTypeInfoLambdaQueryWrapper -> assetDimTypeInfoLambdaQueryWrapper.and(assetDimTypeInfoLambdaQueryWrapper1 -> assetDimTypeInfoLambdaQueryWrapper1.eq(StringUtils.isNotEmpty(assetDimTypeInfo.getCode()),AssetDimTypeInfo::getCode,assetDimTypeInfo.getCode())
                .or()
                .eq(StringUtils.isNotEmpty(assetDimTypeInfo.getName()),AssetDimTypeInfo::getName,assetDimTypeInfo.getName())).eq(assetDimTypeInfo.getParentId() != null,AssetDimTypeInfo::getParentId,assetDimTypeInfo.getParentId())).ne(StringUtils.isNotBlank(assetDimTypeInfo.getId()),AssetDimTypeInfo::getId,assetDimTypeInfo.getId());
        return this.baseMapper.selectList(queryWrapper);
    }
}
